function shopAddToCart(pageURL, ItemID, Object){
	$.get(pageURL + "ajax/shop/add-to-cart/" + ItemID + "/", function(data){
		if(data == "added"){
			Object.innerHTML = "Item added.";
		}
	});
}

function shopChangeItemQuantity(pageURL, ItemID){
	newQuantity = $("#quantity_"+ItemID).val();
	
	$.post(pageURL + "ajax/shop/change-quantity/" + ItemID + "/", { newItemQuantity : newQuantity}, function(data){
		if(data == "updated"){
			
			$.post(pageURL + "ajax/shop/get-item-total/" + ItemID + "/", function(itemTotal){
				$("#shop-item-total-" + ItemID).text(itemTotal);
			});
						
			$.post(pageURL + "ajax/shop/get-cart-total/", function(totalAmount){
				updateCartTotalAmount(totalAmount);
			});
		}
	});
}

function updateCartTotalAmount(amount){
	$("#shop-cart-total").text(amount);
}

function removeCartItem(pageURL, ItemID){
	$.post(pageURL + "ajax/shop/remove-item/", {removeItem : ItemID}, function(data){
		if(data == "removed"){
			$("#shop-cart-item-"+ItemID).fadeOut("slow");
			
			$.post(pageURL + "ajax/shop/get-cart-total/", function(totalAmount){
					updateCartTotalAmount(totalAmount);
			});
			
		}		
	});
}

function clearCart(pageURL){
	$.post(pageURL + "ajax/shop/clear-cart/", function(data){
		if(data == "cleared"){
			location.reload(true);
		}
	});
}

function checkOrder(FormID){
	if($("#name_surname").val() == null || $("#name_surname").val() == "" || $("#address").val() == null || $("#address").val() == "" || $("#e_mail").val() == null || $("#e_mail").val() == "" || $("#telephone").val() == null || $("#telephone").val() == ""){
		
		$("#shopCashierDialoge").dialog({
			autoOpen : true,
			width: 400,
			buttons : {
				"OK" : function(){
					$(this).dialog("close");
				}
			},
			modal : true
		});
		
		if($("#shopCashierDialoge").dialog("isOpen") == false){
			$("#shopCashierDialoge").dialog("open");
		}
		
	}
	else{
		$("#" + FormID).submit();
	}
}